<template>
<div>
  <slot></slot>
</div>
</template>

<script>
export default {
  /*
    columns: [{title: '', key: 'date'},{title: '', key: 'name'},{title: '', key: 'address'}],
    tableData: [
        {
            date: '2016-05-02',
            name: '王小虎',
            address: '上海市普陀区金沙江路 1518 弄'
          }, {
            date: '2016-05-04',
            name: '王小虎',
            address: '上海市普陀区金沙江路 1517 弄'
          }, {
            date: '2016-05-01',
            name: '王小虎',
            address: '上海市普陀区金沙江路 1519 弄'
          }, {
            date: '2016-05-03',
            name: '王小虎',
            address: '上海市普陀区金沙江路 1516 弄'
          }
      ]
  */
  props: {
    columns: {
      require: true,
      Object: Array
    },
    tableData: {
      require: true,
      Object: Array
    },
    tableName: {
      require: false,
      default: '数据列表',
      Object: String
    },
    btnName: {
      require: false,
      default: '导出表格',
      Object: String
    }
  },
  created () {},
  methods: {
    exportData () {
      this.$emit('exportData')
      this.export2Excel(this.columns, this.tableData)
    },
    export2Excel(columns,list){
      require.ensure([], () => {
          const { export_json_to_excel } = require('./excel/Export2Excel');
          let tHeader = []
          let filterVal = []
          console.log(columns)
          if(!columns){
              return;
          }
          columns.forEach(item =>{
              tHeader.push(item.title)
              filterVal.push(item.key)
          })
          const data = list.map(v => filterVal.map(j => v[j]))
          export_json_to_excel(tHeader, data, this.tableName);
      })
    }
  }
}
</script>

<style>

</style>